package org.vectrics.skill.struts.pagelist;

import org.vectrics.SystemException;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.skill.UserEvaluation;
import org.vectrics.skill.struts.SkillWebUtils;
import org.vectrics.struts.VectricsActionData;
import org.vectrics.struts.VectricsStrutsAction;
import javax.servlet.jsp.JspException;

/**
 * @author mmoore
  */
public class UserSkillListEntryFinishedAction extends VectricsStrutsAction {
	private PageListSkillSessionHelper skillSessionHelper = new PageListSkillSessionHelper();
	
	@Override
	protected String doExecute(VectricsActionData actionData) throws JspException {
		String forward = "success";
		Long evaluationId = new Long(actionData.getRequest().getParameter("evaluationId"));
		UserEvaluation evaluation = RecruitServiceLocator.getSkillProvider().findEvaluationById(evaluationId);
		
		this.skillSessionHelper.saveSkillsSelectionsToSessionData(actionData.getRequest(), evaluation.getPerson());
		RecruitServiceLocator.getSkillProvider().saveUserSkillRatingSet(evaluation, this.skillSessionHelper.getSessionSkillRatingSet(actionData.getRequest()));
		if (actionData.wasButtonPressed("next")) {
			forward = "next";
		} else if (actionData.wasButtonPressed("previous")) {
			forward = "previous";
		} else if (actionData.wasButtonPressed("finishedButton")) {
			SkillWebUtils.removeSessionSkillRatingSet(actionData.getRequest());
		} else {
			throw new SystemException("Do not know how to handle button that was pressed");
		}
		return forward;
	}

	
}
